/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.gatech.gellinservlet.presenter;

import edu.gatech.gellinservlet.model.User;
import edu.gatech.gellinservlet.model.UserManager;

/**
 *
 * @author Tyler Powell
 */
public class Authenticator
{
    public Authenticator()
    {
        
    }
    
    /**
     * Checks information give by a user requesting authentication against the
     * UserManager.
     * @param username
     * @param password
     * @param um the UserManager holds all users in the system
     * @return true if the user gave correct info, false otherwise
     */
    public boolean authenticateUser(String username, String password, UserManager um)
    {
        User currentUser = getUser(username, password, um);
        if(currentUser != null)
        {
            currentUser.setLoggedIn(true);
            return true;
        }
        else
        {
            return false;
        }
    }
    
    /**
     * Gives the user with given user name and password from the UserManager
     * @param username
     * @param password
     * @param um the UserManager holds all users in the system
     * @return the user object.
     */
    public User getUser(String username, String password, UserManager um)
    {
        return um.searchOnAuthenticate(username, password);
    }
}
